<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Function Learning2</title>
    <script>
        //解构赋值
        let [x, y, z] = ['aaa', 'bbb', 'ccc'];
        console.log('x=' + x + ',y=' + y + ',z=' + z);
        //嵌套解构赋值
        let [q, [w, e]] = ['qqq', ['www', 'eee']];
        console.log('q=' + q + ',w=' + w + ',e=' + e);

        // 忽略前两个元素，只对z赋值第三个元素
        let [, , o] = ['hello', 'JavaScript', 'ES6'];
        console.log('o=' + o);

        //获取对象中的指定属性
        let person = {
            name: '小明',
            age: 20,
            gender: 'male',
            passport: 'G-12345678',
            school: 'No.4 middle school',
            address: {
                city: 'Beijing',
                street: 'No.1 Road',
                zipcode: '100001'
            }
        };
        let { name, age, passport } = person;
        console.log('name = ' + name + ', age = ' + age + ', passport = ' + passport);
        // 如果person对象没有single属性，默认赋值为true:
        let { name: userName, age: userAge, address: { city }, single = true } = person;

        console.log('userName = ' + userName + ', userAge = ' + userAge + ', city = ' + city + ',single=' + single);



        let x1 = 1, y1 = 2;
        [x1, y1] = [y1, x1];
        console.log('x1='+x1+',y1='+y1);


        //快速获取域名和地址
        var {hostname:domain, pathname:path} = location;
        console.log(domain+':'+path);

        
    </script>
</head>

<body>

</body>

</html>